<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>AJAX calls using Jquery in Servlet</title>

        <!-- <script src="http://code.jquery.com/jquery-latest.min.js"></script>  -->
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
       
        <script>
            $(document).ready(function() {                        
                $('#submit').click(function(event) {  
                    var username=$('#user').val();
            
                    var request = $.ajax({
                    	type: "GET",
                    	url: "/Ajax/ActionServlet",
                		dataType: "text",
                		data: {user:username},
          			  	cache: false
          			});
                    request.done(function( msg ) {
                    	$("#welcometext").text(msg);
          			});
                    
                    request.fail(function(jqXHR, textStatus) {
                    	  alert( "Request failed: " + textStatus );
                    });
                });
            });
        </script>
</head>
<body>
<form id="form1">
<h1>AJAX Demo using Jquery in JSP and Servlet</h1>
Enter your Name:
<input type="text" id="user"/>
<input type="button" id="submit" value="Ajax Submit"/>
<br/>
<div id="welcometext"></div>
</form>
</body>
</html>